#include"String.h"

void test_string_1()
{
	LB::string s2 ;
	cout << s2.c_str() << endl;
	
	LB::string s1("Hello World");
	cout << s1.c_str() << endl;

	s1[0] = 'x';
	cout << s2.c_str() << endl;
	
	for (size_t i = 0; i < s1.size(); i++)
	{
		cout << s1[i] << " ";
	}
	cout << endl;

	LB::string::iterator it1 = s1.begin();
	while (it1 != s1.end())
	{
		(*it1)--;

		++it1;
	}
	cout << endl;

	it1 = s1.begin();
	while (it1 != s1.end())
	{
		cout << *it1 << " ";
		++it1;
	}
	cout << endl;

	for (auto& ch : s1)
	{
		ch++;
	}

	for (auto& ch : s1)
	{
		cout << ch << " ";
	}
	cout << endl;

	const LB::string s3("xxxxx");
	for (auto& ch : s3)
	{
		cout << ch << " ";
	}
	cout << endl;
}

void test_string_2()
{
	LB::string s1("hello world");
	cout << s1.c_str() << endl;

	s1 += ' ';
	s1 += " hello world";
	cout << s1.c_str() << endl;

	LB::string s2("hello world");
	cout << s2.c_str() << endl;
	s2.insert(6, 'x');
	cout << s2.c_str() << endl;

	s2.insert(0, 'x');
	cout << s2.c_str() << endl;

	LB::string s3("hello world");
	cout << s3.c_str() << endl;
	s3.insert(6, "xxxx");
	cout << s3.c_str() << endl;

	s3.insert(0, "xxxxx");
	cout << s3.c_str() << endl;

}

void test_string_3()
{
	LB::string s1("hello world");
	cout << s1.c_str() << endl;

	s1.erase(6, 1);
	cout << s1.c_str() << endl;	
	
	s1.erase(5, 10);
	cout << s1.c_str() << endl;	
	
	s1.erase(4);
	cout << s1.c_str() << endl;
}

void test_string_4()
{
	LB::string s1("hello world");
	cout << s1.find(' ') << endl;
	cout << s1.find("wo") << endl;
}

void test_string5()
{
	LB::string s1("hello world");
	cout << s1.find(' ') << endl;
	cout << s1.find("wo") << endl;

	LB::string s2 = "https://legacy.cplusplus.com/reference/cstring/strstr/?kw=strstr";
	//bit::string s2 = "https://blog.csdn.net/ww753951/article/details/130427526";
	size_t pos1 = s2.find(':');
	size_t pos2 = s2.find('/', pos1 + 3);
	if (pos1 != string::npos && pos2 != string::npos)
	{
		LB::string domain = s2.substr(pos1 + 3, pos2 - (pos1 + 3));
		cout << domain.c_str() << endl;

		//LB::string uri = s2.substr(pos2 + 1);
		//cout << uri.c_str() << endl;
	}
}

void test_string6()
{
	LB::string s1("hello world");
	s1[0] = 'x';
	cout << s1.c_str() << endl;


	cout << s1.c_str() << endl;

}

void test_string7()
{
	LB::string s1("hello world");
	LB::string s2(s1);
	LB::string s3 = s1;
	LB::string s4 = "hello world";

	cout << (s1 == s2) << endl;
	cout << (s1 < s2) << endl;
	cout << (s1 > s2) << endl;
	cout << (s1 == "hello world") << endl;
	cout << ("hello world" == s1) << endl;

	operator<<(cout, s1);
	cout << s1 << endl;
	cin >> s1;
	cout << s1 << endl;
}

int main()
{
	//test_string_1();
	//test_string_2();
	//test_string_3();
	//test_string_4();
	//test_string5();
	test_string7();

	return 0;
}
